Trouble getting attribute value from object

I'm sure I've done this before, but I'm getting an error now when I try to check the value of an object's attribute, I am getting an error with my code:

currMod = read(modName)
for o in currMod do {
    for attribName is skAttrs do {
        if (o.attribName "" != "") {
            find(skAttrs, attribName, numAttr);
            delete(skAttrs, attribName);
            numAttr++;
            put(skAttrs, attribName, numAttr);
        }
    }
}

The error I'm getting is on line 3 of this block of code.  The error says "null string parameter was passed into argument position 2".  Above this for-loop, I have another for-loop that sets up the skAttrs skip list for all the attributes:

for ad in currMod do {
    if (!ad.system) {
        attribName = ad.name"";
        put(skAttrs, attribName, 0);
    }
}

This error isn't making any sense to me.  Please help this intermediate DXL coder.

 

Chris


Christopher Cote - Fri May 24 10:20:12 EDT 2019

Re: Trouble getting attribute value from object
davidcs - Fri May 24 11:52:01 EDT 2019

It looks like you are storing the value of the skiplist as a integer, and then loop through it expecting a string. So do something like this instead:

 

for ad in currMod do {
    if (!ad.system) {
        attribName = ad.name"";
        put(skAttrs, attribName, attribName);
    }
}

 

Re: Trouble getting attribute value from object
llandale - Fri May 24 14:04:04 EDT 2019

the "for variable in SKIP" loop returns the DATA of the Skip, not the "KEY".  In this case you are "put"ting a type "int" (the zero) but retrieving a type "string".

Here is the standatrd Skip loop:

int Data

for Data in skpAttrs do

{  attribName = (string key skpAttrs)

   use attribName

}

 

Also, I don't think it wise to delete from the Skip while in the Skip.  You could just replace it with "put(skiAttrs, attribName, numAttr, true)".

-Louie

Re: Trouble getting attribute value from object
Christopher Cote - Fri May 24 15:26:42 EDT 2019

First of all, I apologize for the extra post with the same question.  Somehow I didn't think my browser was working and I hit Save again.  I figured out how to get the attribute name from the skip list, but now I want to find out if the current object's attribute is blank.  I now have the following code:

for obj in currMod do {
    for o in skAttrs do {
        attribName = (string key skAttrs);
        if (obj.attribName != "") {
            //Get the number saved in skAttrs for this attribute to increment it.
        }
    }
}

However, I get an error on the if-statement, which I'm pretty sure is because the code is trying to find an attribute called attribName instead of the value in attribName.  Sorry if I didn't make that clear originally.

 

Chris

Re: Trouble getting attribute value from object
Mike.Scharnow - Sat May 25 05:43:04 EDT 2019

Christopher Cote - Fri May 24 15:26:42 EDT 2019

First of all, I apologize for the extra post with the same question.  Somehow I didn't think my browser was working and I hit Save again.  I figured out how to get the attribute name from the skip list, but now I want to find out if the current object's attribute is blank.  I now have the following code:

for obj in currMod do {
    for o in skAttrs do {
        attribName = (string key skAttrs);
        if (obj.attribName != "") {
            //Get the number saved in skAttrs for this attribute to increment it.
        }
    }
}

However, I get an error on the if-statement, which I'm pretty sure is because the code is trying to find an attribute called attribName instead of the value in attribName.  Sorry if I didn't make that clear originally.

 

Chris

try

if (obj.attribName"" != "")

i.e. don't "compare an AttrRef_ against a string" but "convert an attribute to a string, i.e. extract the value of a string attribute and compare the value against another string"

Re: Trouble getting attribute value from object
Christopher Cote - Tue May 28 09:15:54 EDT 2019

Arrggh, those double double-quotes got me again.  I seem to always forget that there's a difference between having them and not.  I'm more used to not needing them from my web development coding days.  Thank you Mike.

 

Chris